package com.xm.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
/**
 * @author 陈盼
 * @date 2024-01-02
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Page<T> {
    private List<T> data;
    /**
     * 当前页码
     */
    private Integer pageNumber;
    /**
     * 每页显示数量
     */
    private Integer pageSize;
    /**
     * 总页数
     */
    private Integer totalPages;
    /**
     * 总数
     */
    private Integer count;

    public void setTotalPages(Integer pageSize) {
        // 计算总页数
        this.totalPages =(int) Math.ceil(this.count / (double) pageSize);
    }

    public void setPageNumber(Integer pageNumber) {
        this.pageNumber = pageNumber == null ? 1 : pageNumber;
    }

    public void setCount(Integer count) {
        // 设置总数
        this.count = count;
    }
}
